﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LaughingDog.GameObjects;
using Microsoft.Xna.Framework;

namespace LaughingDog.Components.Shapes
{
    public class EllipseShape : Shape
    {
        private Vector2 mRadius;
        private Single mNumberOfSides = 15;

        public Vector2 Radius { get { return mRadius; } set { mRadius = value; Create(); } }
        public Single NumberOfSides { get { return mNumberOfSides; } set { mNumberOfSides = value; Create(); } }

        public EllipseShape(GameObject gameObject) 
            : base(gameObject)
        {
        }

        private void Create()
        {
            ClearVectors();

            Single max = 2.0f * (Single)Math.PI;
            Single step = max / (Single)mNumberOfSides;
            Single h = 0.0f;
            Single k = 0.0f;

            for (Single t = 0.0f; t < max; t += step)
            {
                // center point: (h,k); add as argument if you want (to circumvent modifying this.Position)
                // x = h + a*cos(t)  -- a is semimajor axis, b is semiminor axis
                // y = k + b*sin(t)
                AddVector(new Vector2((Single)(h + Radius.X * Math.Cos(t)),
                                        (Single)(k + Radius.Y * Math.Sin(t))));
            }

            // then add the first vector again so it's a complete loop
            AddVector(new Vector2((Single)(h + Radius.X * Math.Cos(step)),
                                    (Single)(k + Radius.Y * Math.Sin(step))));
 
        }
    }
}
